package com.tlgen.orm.support.chain;

import com.tlgen.orm.components.rest.model.RequestMethodAndUrl;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

import static com.tlgen.orm.utils.reflect.ReflectionUtils.invokeHttpRequest;

@Component
public class ServiceImplStage implements ExecutionStage {

    @Override
    public boolean shouldExecute(RequestMethodAndUrl requestMethodAndUrl) {
        // 总是执行，无论是否有@SQL
        return true;
    }

    @Override
    public Object execute(HttpServletRequest request,
                          RequestMethodAndUrl requestMethodAndUrl,
                          Map<String, Object> params,
                          Object previousResult) throws Exception {
        return invokeHttpRequest(requestMethodAndUrl);
    }

    @Override
    public boolean shouldTerminate() {
        // 不终止流程，后续可能还有SQL阶段
        return false;
    }

}